package com.thinkgem.jeesite.modules.ta.util;

import java.io.File; 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.xml.parsers.DocumentBuilder; 
import javax.xml.parsers.DocumentBuilderFactory; 

import org.w3c.dom.Document; 
import org.w3c.dom.NodeList;


public class GetLouPanInfoUtil {

	public static Object[] getInfo(HttpServletRequest request) {
		String path = request.getSession().getServletContext().getRealPath("/loupan.xml");
		List<String> lx = new ArrayList<String>();
		List<String> hx = new ArrayList<String>();
		Map<String, String> map = new HashMap<String, String>();
		try {
			File f = new File(path); 
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
			DocumentBuilder builder = factory.newDocumentBuilder(); 
			Document doc = builder.parse(f); 
			
			NodeList nl = doc.getElementsByTagName("leixing");
			for (int i = 0; i < nl.getLength(); i++) { 
				String leixing = doc.getElementsByTagName("name").item(i).getFirstChild().getNodeValue();
				String color = doc.getElementsByTagName("color").item(i).getFirstChild().getNodeValue();
				map.put(leixing, color);
				lx.add(leixing);
			} 
			NodeList n2 = doc.getElementsByTagName("huxing");
			for (int i = 0; i < n2.getLength(); i++) { 
				String huxing = doc.getElementsByTagName("huxing").item(i).getFirstChild().getNodeValue();
				hx.add(huxing);
			} 
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return new Object[]{lx,hx,map};
    }  
	
}
